import router from '@/router/index.js'
import cache from '@u/cache'
import { CurrentUser } from '@/common/user'

const state = {
  currentUser: new CurrentUser(),
  token: JSON.parse(localStorage.getItem('user'))?.token || '',
}

const getters = {
  currentUser: (state) => {
    return state.currentUser
  },
  token: (state) => {
    return state.token
  },
}

const actions = {
  logout({ commit }) {
    cache.removeItem([
      'token',
      'user_name',
      'user_ref_id',
      'user_role_id',
      'user_role_level',
      'user_role_name',
      'city-permission',
      'city-permissionButtonList',
    ])

    router.replace({ path: '/login' })
  },
  // 其他actions
}

export default {
  state,
  getters,
  actions,
}
